<?php
class ServerUtils
{
	function __construct()
	{
		
	}
	/**
	* get currently site domain
	*
	* @param     boolean $isport is return port info in return info.
	* @return    string
	*/
	public static function gethost($isport = false) {
	    $scheme = (isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
	    if(!empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
	        $t = strpos($_SERVER['HTTP_X_FORWARDED_HOST'], ':');
	        if($t > 0) {
	            $host = substr($_SERVER['HTTP_X_FORWARDED_HOST'], 0, $t);
	            $port = substr($_SERVER['HTTP_X_FORWARDED_HOST'], $t+1);
	        } else {
	        $host = $_SERVER['HTTP_X_FORWARDED_HOST'];
	        }
	    } else if(!empty($_SERVER['HTTP_HOST'])) {
	        $t = strpos($_SERVER['HTTP_HOST'], ':');
	        if($t >0) {
	            $host = substr($_SERVER['HTTP_HOST'], 0, $t);
	            $port = substr($_SERVER['HTTP_HOST'], $t+1);
	        } else {
	            $host = $_SERVER['HTTP_HOST'];
	        }
	    } else if(!empty($_SERVER['SERVER_NAME'])) {
	        $host = $_SERVER['SERVER_NAME'];
	    }
	    if(empty($port)) {
	        $port = $_SERVER['SERVER_PORT'];
	    }
	    if($isport) {
	        return $scheme . $host . ':' . $port;
	    } else {
	        return $scheme . $host;
	    }
	}
}
?>